procedure dfs(v:longint); {WAS - Array of boolean; A - matrix; N - number of points}
var j:longint;
begin
was[v]:=true;
for j:=1 to n do 
  if (a[v][j]<>0) and (not was[j]) then dfs(j);
end;
